package hn.cch.druid.query;

import org.springframework.util.StringUtils;

import javax.persistence.Query;

/**
 * 数据库操作符
 *
 * @author CCH
 * @version 2018.08.31
 */
public enum Operator {


    LT("<"),
    GT(">"),
    LGT("<>"),


    EQ("="),
    NOEQ("!="),
    LEQ("<="),
    GEQ(">="),


    LIKE("LIKE"),

    IN("IN"),
    NOIN("NOT IN"),

    NULL("IS NULL"),
    NONULL("IS NOT NULL");

    private String name;

    Operator(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toS(String key, String index) {
        return key + " " + this.name + ":" + (StringUtils.replace(key, ".",
                "_"));
    }

    public void setParameter(Query query, Condition condition, String index) {
        query.setParameter(StringUtils.replace(condition.getKey() + index, ".",
                "_"), condition.getValue());
    }


}
